<?php

class Controller_Store_Add extends Controller
{
	public function execute($request)
	{
		$form = new Form_Store_Add;

		if ($request -> isPost())
		{

			if ($form -> isValid($request -> getPost()))
			{
				$values = $form -> getValues();

				$mongo = DbNosql::inst();
				
				$data = array(
						'_id' => $values['name'],
						'name' => $values['name'],
						'address' => $values['address'],
						'phone'=>$values['phone'],
						'tel'=>$values['tel'],
						'fax'=>$values['fax'],
						'website'=>$values['website'],
						'latlon'=>array('lon'=>0,'lat'=>0),
						'updated'=> new MongoDate(),
				);
				$mongo -> insert('stores', $data, array('safe' => 1));
			}
		}

		$request -> response = View::render(array('form' => $form), 'store/add');

	}

}
